package com.ruoyi.common.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * @创建者：zhouwei
 * @创建时间：2021/5/25
 * @描述：
 */
public class StringUtil {


    public static String underscoreName(String name) {
        if (!StrUtil.hasBlank(name)) {
            return "";
        }
        StringBuilder result = new StringBuilder();
        result.append(StringUtil.lowerCaseName(name.substring(0, 1)));
        for (int i = 1; i < name.length(); i++) {
            String s = name.substring(i, i + 1);
            String slc = StringUtil.lowerCaseName(s);
            if (!s.equals(slc)) {
                result.append("_").append(slc);
            } else {
                result.append(s);
            }
        }
        return result.toString();
    }

    public static String lowerCaseName(String name) {
        return name.toLowerCase(Locale.US);
    }


	/**
	 * 元转分
	 * @param amount
	 * @return
	 */
	public static String yuanToCent(String amount){
		DecimalFormat df = new DecimalFormat("######0");
		Double d = Double.parseDouble(amount) * 100;
		return df.format(d);
	}

	public static String[] yuanToArray(double price){
		String[] ret = new String[7];
		String yuan = yuanToCent(price+"");
		System.out.println("yuan: 补0前 " + yuan);
		yuan = String.format("% 7d", Integer.parseInt(yuan));
		System.out.println("yuan: 补0后 " + yuan);
		ret = yuan.split("");
		return ret;
	}


    /**
     *  喷口
     * @param spout1List
     * @return
     */
    public static String getValveAisle(List<Map<String, Object>> spout1List) {
        if(spout1List == null){
            return "";
        }
        String step1ElectromagneticValveAisle = "";
        if (spout1List != null && spout1List.size() > 0) {
            for (int i = spout1List.size() - 1; i >= 0; i--) {
                Map<String, Object> map = spout1List.get(i);
                if (map.get("isSelect") != null && map.get("isSelect").toString().equals("true")) {
                    step1ElectromagneticValveAisle = step1ElectromagneticValveAisle + "1";
                }else{
                    step1ElectromagneticValveAisle = step1ElectromagneticValveAisle + "0";
                }
            }
        }
        return step1ElectromagneticValveAisle;
    }

    //如果位数不够 补位数
    public static String getSerialNumber(String serial_number,int number_count) {
        String serial_number_str = serial_number + "";
        //如果位数不够 补位数
        if (serial_number_str.length() < number_count) {
            int count = number_count - serial_number_str.length();
            for (int i = 0; i < count; i++) {
                serial_number_str = "0" + serial_number_str;
            }
        }
        return serial_number_str;
    }


    public static void main(String[] args) {


    	String[] ss = yuanToArray(125.0);



        String content = "{\"Id\":\"867435052797073\",\"params\":{\"stepOpenTime\":\"[[\"NO1,1,0,ON\"],[\"NO2,0,0,OFF\"],[\"NO3,0,0,OFF\"],[\"NO4,14,0,ON\"],[\"NO5,0,0,OFF\"],[\"NO6,0,0,OFF\"],[\"NO7,0,0,OFF\"],[\"NO8,17,0,ON\"],[\"NO9,0,0,OFF\"],[\"NO10,0,0,OFF\"],[\"NO11,0,0,OFF\"],[\"NO12,0,0,OFF\"]]\"}}";
        JSONObject bean = JSONUtil.toBean(content, JSONObject.class);
        System.out.println();
    }
}
